Skip to content

perf: reduce bundle size by compressing conversion tables - #70

Merged
polygonplanet merged 4 commits into
masterfrom
feature/compress-tables
Oct 3, 2026
Merged

polygonplanet merged 4 commits into
masterfrom
feature/compress-tables

Conversation

@polygonplanet

@polygonplanet polygonplanet commented Oct 3, 2026 •

Copy link
Copy Markdown
Owner

Store the UTF-8 to JIS conversion tables in a compressed text format and expand them on the first call to convert().

The tables are expanded lazily only when a conversion is actually needed, rather than at module load time, to avoid unnecessary initialization overhead.

Before After
encoding.js 304 KB 148 KB
encoding.min.js 229 KB 88 KB
encoding.min.js (gzip) 76 KB 39 KB

The first encode now has an extra step to expand the tables (about 7ms on Node 24), but loading is faster (15ms -> 3.6ms) because the tables are much smaller, so load + first conversion is faster overall (16ms -> 11ms).
For decoding, expanding the tables takes about as long as the previous init_JIS_TO_UTF8_TABLE() did, even though it now builds both directions at once.

Conversion results are unchanged.

Follow-up: Added tests/gen-compressed-table.js in 48a884f to generate the compressed conversion tables in src/ from the readable source tables in tests/.

@polygonplanet
polygonplanet merged commit 3f992e1 into master Oct 3, 2026
18 checks passed
@polygonplanet
polygonplanet deleted the feature/compress-tables branch October 3, 2026 17:29
@polygonplanet polygonplanet changed the title Reduce bundle size by compressing conversion tables perf: reduce bundle size by compressing conversion tables Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant